<div class="layui-fluid" id="VIEW-student_list-table" lay-title="学生列表">
  <div class="layui-row layui-col-space10">
    <div class="layui-col-md10">
      <div class="layui-card">
        <div class="layui-card-body nepadmin-table-full">
          <div class="layui-btn-container nepadmin-pad-t10 nepadmin-pad-l10">
            <div class="layui-btn layui-btn-sm table-action" data-type="add">添加</div>
            <div class="layui-btn layui-btn-sm layui-btn-primary table-action" data-type="modify">修改</div>
            <div class="layui-btn layui-btn-sm layui-btn-primary table-action" data-type="del">删除</div>
            <div class="layui-btn layui-btn-sm layui-btn-primary table-action" data-type="move">变更为教师</div>
            <div class="layui-btn layui-btn-sm layui-btn-primary table-action" data-type="refresh">刷新页面</div>

          </div>
          <table id="student_list-table" lay-filter="student_list-table"></table>
        </div>
      </div>
    </div>
    <div class="layui-col-md2">
      <div class="layui-card">
        <div class="layui-card-header">筛选数据</div>
        <div class="layui-card-body">
          <div class="layui-row layui-col-space10 layui-form">
            <div class="layui-col-md12 layui-col-xs4">
              <select name="type">
                <option value="">学院</option>
                <option value="1">信息科学与工程学院</option>
                <option value="2">信息科学与工程学院1</option>
                <option value="3">信息科学与工程学院2</option>
              </select>
            </div>
            <div class="layui-col-md12 layui-col-xs4">
              <select name="status">
                <option value="">专业</option>
                <option value="1">通信工程</option>
                <option value="2">电子信息工程</option>
                <option value="3">建筑电气自动化</option>
              </select>
            </div>
            <div class="layui-col-md12 layui-col-xs4">
              <select name="group">
                <option value="">班级</option>
                <option value="1">1501</option>
                <option value="2">1502</option>
              </select>
            </div>
            <div class="layui-col-md12">
              <div class="layui-row layui-col-space10">
                <div class="layui-col-md6 layui-col-xs6">
                  <input type="text" class="layui-input" placeholder="学号" />
                </div>
                <div class="layui-col-md6 layui-col-xs6">
                  <input type="text" class="layui-input" placeholder="学号" />
                </div>
              </div>
            </div>
            <div class="layui-col-md12 layui-col-xs12">
              <div class="layui-row layui-col-space10">
                <div class="layui-col-xs6">
                  <div class="layui-btn layui-btn-sm layui-btn-fluid">筛选</div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-btn layui-btn-sm layui-btn-fluid layui-btn-primary">重置</div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="layui-card nepadmin-font-12">
        <div class="layui-card-header">
          <i class="layui-icon">&#xe78c;</i> 帮助中心</div>
        <div class="layui-card-extra">
          <a>进入</a>
        </div>
        <div class="layui-card-body">

        </div>
      </div>

    </div>
  </div>

  <script type="text/html" id="TPL-student_list-table-class">
      {{d.speciality}}{{d.class }}
    </script>

</div>
<script>
  layui.use(['admin', 'table', 'form', 'dropdown', 'jquery'], function (admin, table, form, dropdown, $) {
    var view = $('#VIEW-student_list-table');

    var tableFilter = 'student_list-table';
    form.render();
    table.render({
      elem: '[lay-filter="' + tableFilter + '"]',
      api: 'students',
      height: 'full-165',
      cols: [[
        { title: '', type: 'checkbox', fixed: true, width: 60 },
        { title: '学号', field: 'username', width: 120 },
        { title: '姓名', field: 'name', align: 'center', width: 80 },
        { title: '性别', field: 'sex', align: 'center', width: 60 },
        { title: '学院', field: 'institute', width: 160 },
        { title: '专业班级', templet: '#TPL-student_list-table-class', width: 120 },
        { title: '手机MAC地址', field: 'phone_mac', width: 150 },
        { title: '电脑MAC地址', field: 'pc_mac', width: 150 }]]
    });



    view.find('.table-action').click(function () {
      var type = $(this).attr('data-type')
      if (type == 'refresh') {
        //刷新当前页
        layui.view.tab.refresh()

        //刷新一个指定页，不用传入页面的参数
        //layui.view.tab.refresh('/index')

        return false;
      }

      if (type == 'add') {
        admin.popup({
          url: '/user/user_set',
          title: '添加学生',
          area: 'auto',
          data: {
            username: "",
            class: ""
          }
        })
        return false;
      }

      var checkedData = table.checkStatus(tableFilter).data;
      if (checkedData.length == 0) {
        layer.msg('请选择操作对象');
      } else {
        if (type == 'modify') {
          if (checkedData.length == 1) {
            admin.popup({
              url: '/user/user_set',
              title: '修改学生信息',
              area: 'auto',
              data: checkedData[0]
            })
          } else {
            layer.msg('请勿同时选择多个操作对象');
          }

        } else {
          var name_list = '';
          var username_list = '';
          for (var index in checkedData) {
            name_list = name_list + checkedData[index].name + ' ';
            username_list = username_list + checkedData[index].username + ',';
          }
          var post_data = new Object();
          post_data.usernames = username_list;
          if (type == 'del') {
            admin.modal.warn(
              '确认删除下列用户？<br/>' + name_list, {
                btn: ['确认', '取消'],
                yes: function (index, layero) {
                  post_data.action = 'del';
                  admin.post({
                    api: 'students',
                    data: post_data,
                    success: function (res) {
                      if (res.code == 200) {
                        layer.msg('删除成功');
                      } else {
                        layer.msg('删除失败');
                      }
                    },
                  });
                },
                area: 'auto'
              }
            );
          } else if (type == 'move') {
            admin.modal.warn(
              '确认将下列用户变更身份为教师？<br/>' + name_list, {
                btn: ['确认', '取消'],
                yes: function (index, layero) {
                  post_data.action = 'mov';
                  admin.post({
                    api: 'teachers',
                    data: post_data,
                    success: function (res) {
                      if (res.code == 200) {
                        layer.msg('身份变更成功');
                      } else {
                        layer.msg('身份变更失败');
                      }
                    },
                  });
                },
                area: 'auto'
              }
            );
          }
        }
        //layer.msg($(this).html() + checkedCount + '项');
      }

    })


  })
</script>